/* Copyright (c) 2008 Google Inc.
*  Copyright (c) 2009 Pierre Henri Kuate.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public static class UpdateFetchAppData
{
    public static void Run()
    {
        var c = new org.opensocial.client.OpenSocialClient("orkut.com");

        c.setProperty(org.opensocial.client.OpenSocialClient.Properties.REST_BASE_URI,
                      "http://sandbox.orkut.com/social/rest");
        //c.setProperty(org.opensocial.client.OpenSocialClient.Properties.RPC_ENDPOINT,
        //              "http://www.orkut.com/social/rpc");

        // Credentials provided here are associated with the gadget located at
        // http://opensocial-resources.googlecode.com/svn/samples/rest_rpc/sample.xml;
        // If you install this gadget, you can substitute your own OpenSocial ID
        // for the one used below and fetch your profile data and friends
        c.setProperty(org.opensocial.client.OpenSocialClient.Properties.CONSUMER_SECRET, "uynAeXiWTisflWX99KU1D2q5");
        c.setProperty(org.opensocial.client.OpenSocialClient.Properties.CONSUMER_KEY, "orkut.com:623061448914");
        c.setProperty(org.opensocial.client.OpenSocialClient.Properties.VIEWER_ID, "03067092798963641994");

        System.Random generator = new System.Random();

        // Update app data for key "key1" -- store a random number under the
        // given "key1" for the current user
        c.updatePersonAppData("key1", generator.Next().ToString());

        // Retrieve all key-value pairs stored as app data for the specified user
        // including the pair added above
        org.opensocial.data.AppData appData = c.fetchPersonAppData("03067092798963641994");

        System.Console.Out.WriteLine("----------");

        // Print all app data values associated with the user
        foreach (string key in appData.getFieldNamesForUser("03067092798963641994"))
        {
            System.Console.Out.WriteLine(key + ": " +
                appData.getStringForUser("03067092798963641994", key));
        }

        System.Console.Out.WriteLine("----------");
    }
}